﻿using System;
using System.Drawing;
using System.Collections.Generic;
using System.Text;
using DirectUI.Mobile.UI.Drawing.GdiPlus;
namespace DirectUI.Mobile.UI.Controls
{
    public class DirectUIComboBoxItem : DirectUIControl
    {
        public DirectUIComboBoxItem()
        {
            this.Height = 20;
            this.ForeColor = Color.Black;
            this.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular);
        }
        public DirectUIComboBoxItem(string text,string value)
        {
            this.Text = text;
            this.Value = value;
            this.Height = 20;
            this.ForeColor = Color.Black;
            this.Font = new Font(FontFamily.GenericSerif, 10, FontStyle.Regular);
        }
        public override bool Active
        {
            get
            {
                return true;
            }
        }
        public string Text
        {
            get;
            set;
        }
        public string Value
        {
            get;
            set;
        }
        private SolidBrush brush = new SolidBrush(Color.Black);
        public Color ShadowColor { get; set; }
        public override void OnPaint(DirectUIPaintEventArgs e)
        {
            base.OnPaint(e);
      //     e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.ControlBounds);

            if (!string.IsNullOrEmpty(Text))
            {
                PaintDefaultText(e, Text);
            }
        }
        protected override void OnPaintBackground(DirectUIPaintEventArgs e)
        {   
               
                if (!BackColor.IsEmpty && BackColor != Color.Transparent)
                {
                    Graphics g = e.Graphics;
                    if (BackColor.A == 255 || BackColor.A == 0)
                    {
                        SolidBrush brush = Brushes.GetBrush(BackColor);
                        g.FillRectangle(brush, e.ControlBounds);
                    }
                    else
                    {
                        using (GraphicsPlus gp = new GraphicsPlus(g))
                        {
                            using (SolidBrushPlus brush = new SolidBrushPlus(BackColor))
                            {
                                gp.FillRectangle(brush,e.ControlBounds);
                            }
                        }
                    }
                }
            
        }
        protected void PaintDefaultText(DirectUIPaintEventArgs e, string text)
        {
            Graphics g = e.Graphics;
            Rectangle bounds = e.ControlBounds;
            bounds.Inflate(e.ScaleX(-3), e.ScaleY(-1));
            //bounds.Y += e.ScaleY(-1);
            if (bounds.Height > 0 && bounds.Width > 0)
            {
                if (ShadowColor.IsEmpty)
                {
                    brush.Color = Enabled ? ForeColor : Color.Silver;
                    g.DrawString(text, Font, brush, RectFFromRect(bounds));
                }
                else
                {
                    DirectUI.Mobile.UI.Drawing.GdiPlus.GdiExt.DrawStringShadow(g, text, Font, ForeColor, ShadowColor, bounds, new StringFormat());
                }
            }
        }
    }
}
